﻿                                            using AutoMapper;
using B.S.Data.MES.API.Applications.AccountApplication.Command;
using B.S.Domain.Accounts;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.AccountApplication.CommandHandler
{
    /// <summary>
    /// 实现账户更新命令处理器
    /// </summary>
    public class AccountUpdateCommandHandler : IRequestHandler<AccountUpdateCommand, APIRequst<int>>
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="accountRepository">用户表</param>
        public AccountUpdateCommandHandler(IBaseRepository<Account> accountRepository,IMapper mapper)
        {
            AccountRepository = accountRepository;
            Mapper = mapper;
        }
        /// <summary>
        /// 用户表
        /// </summary>
        public IBaseRepository<Account> AccountRepository { get; }
        public IMapper Mapper { get; }

        /// <summary>
        /// 处理账户更新命令
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIRequst<int>> Handle(AccountUpdateCommand request, CancellationToken cancellationToken)
        {
                request.Data.UpdateTime = DateTime.Now;
          
              await  AccountRepository.Update(request.Data);
            return new APIRequst<int>
            {
                Code = RequstCode.成功,
                Msg = "更新成功",
                Data = 1
            };
        }
    }
}
